package com.gdit.zax.utils;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 界面跳转
 * @author ping
 *
 */
public class Repost {
	public static void nologin(HttpServletResponse response) throws IOException {
		response.sendRedirect("nologin.jsp");
	}
	
	public static void dberror(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		Repost.message("数据库服务器出错，请联系管理员!", request, response);
	}
	
	public static void message(String message,HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setAttribute("message", message);
		request.getRequestDispatcher("message.jsp").forward(request, response);
//		request.getRequestDispatcher("applyteacher.jsp").forward(request, response);
	}
	
	public static void success(String jsp,HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.getRequestDispatcher(jsp).forward(request, response);
	}
	
	public static void back (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String backurl = request.getHeader("Referer");
		if (backurl!=null) {
			int startindex = backurl.lastIndexOf("/");
			backurl = backurl.substring(startindex, backurl.length());
			success(backurl, request, response);
		} else {
			message("返回上一级页面错误!", request, response);
		}
	}
}
